<%-- 
    Document   : CMS_staff
    Created on : Nov 25, 2013, 2:49:15 AM
    Author     : BibooChung
--%>



<!DOCTYPE html>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import = "java.util.*" import="cart.hibernate.authLevel.*" import="cart.hibernate.staff.*" import="cart.*,java.net.*,java.text.*" %>
<jsp:useBean id = "authLevelManager" scope= "request" class = "cart.hibernate.authLevel.ManageAuthLevel" />
<jsp:useBean id = "staffManager" scope= "request" class = "cart.hibernate.staff.ManageStaff" />

<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
        <script type="text/javascript" src="//ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
        <script type="text/javascript" src="js/bootstrap.min.js"></script>
        <script type="text/javascript" src="js/CMS.js"></script>
        <link type="text/css" href="css/CMS.css" rel="stylesheet" />
        <link href="css/bootstrap.min.css" rel="stylesheet" media="screen">
        <link href="css/font-awesome.min.css" rel="stylesheet" media="screen">
        <link href="css/bootflat.css" rel="stylesheet" media="screen">
        <link href="css/bootflat-extensions.css" rel="stylesheet" media="screen">
        <link href="css/bootflat-square.css" rel="stylesheet" media="screen">
    </head>
    <body>
        <jsp:include page="CMS_menu.html" />
        <h1>Manage Staff</h1>

        <!-- Table with integrated management -->
        <table style="margin-bottom:20px;" class="table table-striped">
            <thead>
                <tr>
                    <th>Staff ID</th>
                    <th>Staff Password</th>
                    <th>Authentication Level</th>
                    <th>Update?</th>
                    <th>Delete?</th>
                </tr>
            </thead>
            <tbody>
                <%
                //    List authLevelList = authLevelManager.getAllStaff();
               //     Iterator iterStaff = authLevelList.iterator();
                    List staffList = staffManager.getAllStaff();
                    List authLevelList = authLevelManager.getAllAuthLevel();

                    Iterator iterStaff = staffList.iterator();
                    Iterator iterAuthLevel = authLevelList.iterator();

                    while (iterStaff.hasNext())
                    {

                        Staff staff = (Staff) iterStaff.next();
                %>
                        <tr>
                            <form action="ManageStaffServlet" method="post">
                                <input type="hidden" name="staffId" value="<%= staff.getId() %>"> 
                                <td>
                                    <%= staff.getId() %>
                                </td>
                                <td>
                                    <input type="text" name="password" value="<%= staff.getPassword() %>" class="form-control" />
                                </td>
                                <td>
                                    <select name="authLevelId" class="form-control">
                                        <%
                                            while (iterAuthLevel.hasNext())
                                            {
                                                AuthLevel authLevel = (AuthLevel) iterAuthLevel.next();
                                                //out.print("<option value='" + authLevel.getAuthLevel() + "'");
                                                //out.print((authLevel == staff.getAuthLevel()) ?  "' selected='selected'" : "'");               

                                              //  out.print("<input type='hidden' name='authLevelId' value='" + authLevel.getAuthLevelId() + "'>");                                
                                                if(authLevel.getAuthLevelId() == staff.getAuthLevel().getAuthLevelId())
                                                    out.print("<option value='" + authLevel.getAuthLevelId() + "' selected='selected'>" + authLevel.getAuthLevel() + "</option>");
                                                else
                                                    out.print("<option value='" + authLevel.getAuthLevelId() + "'>" + authLevel.getAuthLevel() + "</option>");
                                            }
                                            iterAuthLevel = authLevelList.iterator();
                                        %>
                                    </select>
                                </td>
                                <td>
                                    <input type="submit" name="submit" value="update" class="btn btn-primary">
                                </td>
                                <td>
                                    <input type="submit" name="submit" value="delete" class="btn btn-danger">
                                </td>
                            </form>
                        </tr>
                <%        
                    }
                %>
            </tbody>
        </table>
                    <table>
                        <form action="ManageStaffServlet" method="post">
                            <td>Enter new staff : </td>
                            <td><input type="text" name="password" id="password" placeholder="Password" class="form-control"></td>
                            <td>
                                <select name="authLevelId" class="form-control">
                                    <%
                                        while (iterAuthLevel.hasNext())
                                        {
                                            AuthLevel authLevel = (AuthLevel) iterAuthLevel.next();
                                  //          out.print("<input type='hidden' name='authLevelId' value='" + authLevel.getAuthLevelId() + "'>");
                                            out.print("<option value='" + authLevel.getAuthLevelId() + "'>" + authLevel.getAuthLevel() + "</option>");
                                        }
                                        iterAuthLevel = authLevelList.iterator();
                                    %>
                                </select>
                            </td>
                            <td><input type="submit" name="submit" value="add" class="btn btn-primary"></td>
                        </form>
                    </table>
    </body>
</html>